<!DOCTYPE html>
<html lang="en">
<head>

    <!-- 页面meta -->

    <meta charset="utf-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <title>请假信息主页</title>

    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">

    <!-- 引入样式 -->

    <link rel="stylesheet" href="../plugins/elementui/index.css">

    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">

    <link rel="stylesheet" href="../css/style.css">

</head>

<body class="hold-transition">

<div id="app">
    <div class="app-container">

        <center>
            <el-button type="primary" plain @click="myself">宿舍人员信息</el-button>
            <el-button type="primary" plain @click="leaves">请假</el-button>
            <el-button type="primary" plain @click="helperCheck">去查寝</el-button>
            <el-button type="primary" plain @click="checkDorm">我的查寝信息</el-button>
            <el-button type="primary" plain @click="checknotice">查看通告</el-button>
            <el-button type="danger" plain @click="tc">退出登陆</el-button>
        </center>
        <div class="box">
            <center>
                <div class="filter-container">
<!--                    <el-input-->
<!--                            placeholder="请输入学号"-->
<!--                            prefix-icon="el-icon-search"-->
<!--                            style="width: 220px"-->
<!--                            v-model="sno"-->
<!--                    >-->
<!--                    </el-input>-->
<!--                    <el-input-->
<!--                            placeholder="请输入姓名"-->
<!--                            prefix-icon="el-icon-search"-->
<!--                            style="width: 220px;margin-left: 5px"-->
<!--                            v-model="sname"-->
<!--                    >-->
<!--                    </el-input>-->
<!--                    <el-button type="primary" icon="el-icon-search" style="margin-left: 5px" @click="getAll">搜索</el-button>-->
                    <el-button type="primary" class="butT" @click="handleCreate()">我要请假</el-button>
                </div>
            </center>
            <!--stripe highlight-current-row/-->
            <el-table size="small" current-row-key="id" :data="dataList" >

                <el-table-column prop="leaveid" align="center" label="编号" hidden></el-table-column>

                <el-table-column prop="beginTime" label="开始时间" align="center"></el-table-column>
                <el-table-column prop="endTime" label="结束时间" align="center"></el-table-column>
                <el-table-column prop="reason" label="原因" align="center"></el-table-column>
                <el-table-column label="操作" align="center" width="180px">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">修改</el-button>
                        <el-button type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>

            </el-table>

            <center>
                <div class="block">
                    <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-sizes="[2, 5, 10, 15]"
                            :page-size="pagination.pageSize"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="pagination.total">
                    </el-pagination>
                </div>
            </center>

        </div>
        <!--添加框-->
        <div class="add-form">
            <el-dialog title="添加信息" :visible.sync="dialogFormVisible">
                <el-form ref="dataAddForm" :model="studentAddLeave"  label-position="right" label-width="100px">
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="编号" >
                            <el-input
                                 placeholder="请输入内容"
                                 v-model="studentAddLeave.sid"
                                 :disabled="true">
                            </el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="开始时间" >
                                <span class="demonstration"></span>
                                <el-date-picker
                                        v-model="studentAddLeave.beginTime"
                                        type="datetime"
                                        value-format="yyyy-MM-dd HH:mm:ss"
                                        placeholder="选择开始时间">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="结束时间" >
                                <div class="block" style="display: inline">
                                    <span class="demonstration"></span>
                                    <el-date-picker
                                            v-model="studentAddLeave.endTime"
                                            type="datetime"
                                            value-format="yyyy-MM-dd HH:mm:ss"
                                            placeholder="选择结束时间">
                                    </el-date-picker>
                                </div>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="请假原因" >
                                <el-input
                                        v-model="studentAddLeave.reason"
                                        type="textarea"
                                        :autosize="{ minRows: 2, maxRows: 4}"
                                        placeholder="请输入原因"
                                >
                                </el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="cancel()">取消</el-button>
                    <el-button type="primary" @click="handleEdit()">确定</el-button>
                </div>
            </el-dialog>
        </div>

        <!--修改框-->
        <div class="add-form">
            <el-dialog title="修改信息" :visible.sync="dialogFormVisible4Edit">
                <el-form ref="dataAddForm" :model="studentUpdateLeave"  label-position="right" label-width="100px">
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="编号" >
                                <el-input
                                        placeholder="请输入内容"
                                        v-model="studentUpdateLeave.leaveid"
                                        :disabled="true">
                                </el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="开始时间" >
                                <span class="demonstration"></span>
                                <el-date-picker
                                        v-model="studentUpdateLeave.beginTime"
                                        type="datetime"
                                        value-format="yyyy-MM-dd HH:mm:ss"
                                        placeholder="选择开始时间">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="结束时间" >
                                <div class="block" style="display: inline">
                                    <span class="demonstration"></span>
                                    <el-date-picker
                                            v-model="studentUpdateLeave.endTime"
                                            type="datetime"
                                            value-format="yyyy-MM-dd HH:mm:ss"
                                            placeholder="选择结束时间">
                                    </el-date-picker>
                                </div>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="请假原因" >
                                <el-input
                                  v-model="studentUpdateLeave.reason"
                                  type="textarea"
                                  :autosize="{ minRows: 2, maxRows: 4}"
                                  placeholder="请输入内容"
                                >
                                </el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="cancel()">取消</el-button>
                    <el-button type="primary" @click="Edit()">确定</el-button>
                </div>
            </el-dialog>
        </div>

    </div>
</div>

</body>

<!-- 引入组件库 -->

<script src="../js/vue.js"></script>

<script src="../plugins/elementui/index.js"></script>

<script type="text/javascript" src="../js/jquery.min.js"></script>

<script src="../js/axios-0.18.0.js"></script>

<script>
    var vue = new Vue({
        el: '#app',
        data:{
            dataList: [],//当前页要展示的列表数据
            dialogFormVisible: false,//添加表单是否可见
            dialogFormVisible4Edit:false,//编辑表单是否可见
            dialogFormVisibleBorrow:false, //编辑借书表单是否可见
            sno: undefined,
            sname: undefined,
            sid: undefined,
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize:2,//每页显示的记录数
                total:0,//总记录数
            },
            //添加框
            studentAddLeave:{
                reason: undefined,
                endTime: undefined,
                beginTime:undefined,
                sid:this.sid,
            },
            //添加框
            studentUpdateLeave:{
                reason: undefined,
                endTime: undefined,
                beginTime:undefined,
                leaveid:undefined,
                sid:this.sid,
            },
            total:'',
            borrow:{
                borrowNums:'',
                id:''
            },
            one:"",
            two:"",
            three:[]
        },

        //钩子函数，VUE对象初始化完成后自动执行
        created(){
            this.getSession();
        },
        mounted() {
            setTimeout(()=>{//不延时没拿到sid就执行了
                this.getAll();
            },50)
        },

        methods: {
            //列表
            getAll() {
                    axios.get("http://localhost:80/leaves/sLPage",{
                        params:{
                            pageNum: this.pagination.currentPage,
                            pageSize: this.pagination.pageSize,
                            sid: this.sid
                        }
                    }).then(res=>{
                        console.log("666666666666"+this.sid)
                        console.log(res)
                        this.dataList=res.data.data.records;
                        this.pagination.total=res.data.data.total
                    })

            },
            //获得session
            getSession(){
                axios.get("http://localhost:80/checkdorm/getSession").then(res=>{
                    if (res.data.data==null){
                        this.$message.error(res.data.msg)
                        window.location.href="http://localhost:80/xu/pages/studentLogin.html"
                    }
                    window.localStorage.setItem("sid",res.data.data);
                   this.sid= res.data.data
                   //this.sid= window.localStorage.getItem("sid");
                    console.log(this.sid)
                })

            },
            //添加
            handleEdit(){
                axios.post("http://localhost:80/leaves/add",this.studentAddLeave).then((res)=>{
                   if (res.data.key==500){
                       this.$message.error(res.data.msg)
                   }else {
                       this.$message.success(res.data.msg)
                   }
                   this.dialogFormVisible=false;
                   this.studentAddLeave.endTime=null
                   this.studentAddLeave.beginTime=null
                   this.studentAddLeave.reason=null
                    this.getAll();
                })
            },

            handleCreate() {
                this.dialogFormVisible=true;
                this.studentAddLeave.sid=this.sid
                this. resetForm();
            },

            handleDelete(row){
                this.$confirm('此操作将永久删除这条请假信息, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.delete("http://localhost:80/leaves/del/"+row.leaveid).then((res)=>{
                        this.$message.success(res.data.msg)
                        this.getAll()
                    })
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            //重置表单
            resetForm() {
                this.formData={};
            },
            //修改
            handleUpdate(row){
                this.dialogFormVisible4Edit=true
                this.studentUpdateLeave=row
                this.studentUpdateLeave.sid=this.sid
            },
            Edit(){
                axios.put("http://localhost:80/leaves/update",this.studentUpdateLeave).then((res)=>{
                    if (res.data.key==500){
                        this.$message.error(res.data.msg)
                    }else {
                        this.$message.success(res.data.msg)
                    }

                    this.studentUpdateLeave.endTime=null
                    this.studentUpdateLeave.beginTime=null
                    this.studentUpdateLeave.reason=null
                    this.dialogFormVisible4Edit=false;
                    this.getAll();
                })
            },

            //取消
            cancel(){
                this.dialogFormVisible=false;
                this.dialogFormVisible4Edit=false;
                this.dialogFormVisibleBorrow=false;
                this.borrow.borrowNums=''
                this.borrow.borrowNums=''
                this.$message.info("当前操作取消");
                this.getAll();
            },
            handleCurrentChange(val){
                this.pagination.currentPage=val;
                this.getAll();
            },
            handleSizeChange(val){
                this.pagination.pageSize=val;
                this.getAll();
            },
            tc() {
                this.$confirm("确定退出账户？","提示",{type:"info"}).then(()=>{
                    axios.post("http://localhost/logout").then((res)=>{
                        window.location.href = '/xu/pages/studentLogin.html'
                    })
                })
            },
            cancel(){
                this.dialogFormVisible4Edit=false;
            },
            leaves(){
                window.location.href="http://localhost:80/wu/pages/studentLeave.html"
            },
            myself(){
                window.location.href="http://localhost:80/xu/pages/myself.html"
            },
            checknotice(){
                window.location.href="http://localhost:80/xu/pages/stuboard.html"
            },
            checkDorm(){
                window.location.href="http://localhost:80/wu/pages/studentCheckDorm.html"
            },
            helperCheck(){
                window.location.href="http://localhost:80/wu/pages/helperCheck.html"
            }




        }
    })

</script>
</html>